<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Groups/classes/PhpFox_ComponentGroupForumTopics.class.php, $Author:  $ */



/** Component for Group Forum Topics
 * @version $Id: PhpFox_ComponentGroupForumTopics.class.php
 *  Max Kovrigovich
 * @package module.groups
 */
class PhpFox_Mod_Groups_ComponentGroupForumTopics extends BaseComponent
{
    /** Processing method
     */

    function process()
    {
        //check permissions
        $oSecurityService = App::getModuleService('Account', 'Security');
		/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
		$oSecurityService->checkPerm('groups', array('read_only', 'full'));

        $oGroupsService = $this->_oModule->getService('Groups');
        /* @var $oGroupsService PhpFox_Mod_Groups_ServiceGroups */

        $oForumService = $this->_oModule->getService('GroupForum');
        /* @var $oForumService PhpFox_Mod_Groups_ServiceForum */

        $oReq = &App::getRequest();
        /* @var $oReq Request */

        $oUrl = &App::getUrl();
        /* @var $oUrl Url */

        $oTpl = $this->_oModule->getTemplate();

        $iGroupId = $oReq->getInt('id', 0);

        $aGroupData = $oGroupsService->getGroupData($iGroupId);

        if ( $aGroupData['pub_forum'] == 'No' && !( (App::getUser('user') AND $oGroupsService->isMember($iGroupId, App::getUser('user'))) OR App::isStaff()) )
        {
        	App::gotoUrl('public.groups');
        }

        if(!$iGroupId)
        {
            App::gotoUrl('public.groups');
		}

        App::loadClass('Pager');
        $iPageSize = App::getParam('public.pagesize');

        list($aTopics, $iCnt) = $oForumService->getTopicList(array('group_id'=>'= '.$iGroupId, 'type'=>'= ""'), $oReq->getInt('page', 1), $iPageSize);

        $iPage = $oReq->getInt('page', 1);
        $oPager = &new Pager($iCnt, $iPage, $iPageSize);

        $iFrom = $oPager->getOffset($iPage, $iPageSize);
        $iTo = (($iFrom + $iPageSize) > $iCnt) ? $iCnt : ($iFrom + $iPageSize);

        $oTpl->assignSrc(array(
            'iFrom'         => ($iCnt) ? ($iFrom + 1) : 0,
            'iTo'           => $iTo,
            'aPaging'       => $oPager->getInfo($oUrl),
            'iCnt'          => $iCnt,
            'aTopics'    => $aTopics,
            'aGroupData' => $aGroupData,
	        'sImageUrl'     => App::getParam('user.pic.url'),
            'iDate'      => time(),
	        'sMonthDateFormat' => App::getParam('format.monthdate%'),
            'sMonthDateFormatDot' => App::getParam('format.monthdatedot'),
        ));
        $sHtml = $oTpl->fetch('GroupForumTopics.html');
        return $sHtml;
    }
}
?>